Remote Connection
SSH
- Connect to a remote server
- syntax user@ip-address
ssh root@198.77.56.221
SCP
- The scp(secure copy) command copies files or directories between a local and a remote system or between two remote systems.
scp filename root@198.77.56.221:/path/
Rsync
- Source
- Rsync, which stands for remote sync, is a remote and local file synchronization tool.
- It uses an algorithm to minimize the amount of data copied by only moving the portions of files that have changed.
rsync -av -e ssh --exclude='*.env' --exclude='node_modules' local-folder-name root@198.58.173.149:/var/www/folder-name
- -a = archive
- This flag syncs recursively and preserves symbolic links, special and device files, modification times, groups, owners, and permissions.
- Recommended than -r
- -v = verbose
- -e = specify the remote shell to use
- --exclude = ignore
Public Key
Access Public Key
cat ~/.ssh/id_rsa.pub
Generate Ssh Key
ssh-keygen -o
How To Set Up SSH Key Pair
- Source
- Though SSH supports password-based authentication, it is generally recommended that you use SSH keys instead.
- SSH keys are a more secure method of logging into an SSH server, because they are not vulnerable to common brute-force password hacking attacks.
Steps to SSH Key Pair
- Generate Ssh Key
- Copy the key to the server you want to connect
ssh-copy-id username@your_server_address
#if you the key with other name and path
ssh-copy-id -i .ssh/githubKey.pub user@server
Disabling Password-based SSH Authentication (Optional)
sudo nano /etc/ssh/sshd_config
- This command will open up the file within the
nano
text editor. Find the line in the file that includesPasswordAuthentication
(or create the line if it doesn’t exist), make sure it is not commented out with a#
at the beginning of the line, and change it tono
:
PasswordAuthentication no
- Reload the
sshd
service to put these changes into effect
sudo systemctl reload sshd